﻿<%@ WebHandler Language="C#" Class="LotteryData" %>

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Data;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Net;
using System.Linq;

using Newtonsoft.Json;


public class LotteryData : MyAjaxBase
{

    /// <summary>
    /// 处理程序请求
    /// </summary>
    /// <param name="context"></param>
    public override void ProcessRequest(HttpContext context)
    {
        try
        {
            string operType = ReadRequest.RequestString("t");

            switch (operType)
            {
                case "GetLotteryannouncement":
                    GetLotteryannouncement(context);
                    break;
                case "GetTop10Data_ssq":
                    GetTop10Data_ssq(context);
                    break;
                //case "GetLoteryNo_dlt":
                //    GetLoteryNo_dlt(context);
                //    break;
                case "GetTop10Data_dlt":
                    GetTop10Data_dlt(context);
                    break;
                case "GetTop10Data_qlc":
                    GetTop10Data_qlc(context);
                    break;
                case "GetCurrentLotteryQs":
                    GetCurrentLotteryQs(context);
                    break;
                case "FaBuMeiTiYuCe"://发布预测方案
                    FaBuMeiTiYuCe(context);
                    break;
                case "FaBuYuCe"://发布预测
                    FaBuYuCe(context);
                    break;
                case "GenTie"://跟帖
                    GenTie(context);
                    break;
                case "YanZhengMa"://验证码是否正确
                    YanZhengMa(context);
                    break;
                case "GetYucestatistics"://获取会员发布预测的数字
                    GetYucestatistics(context);
                    break;
                case "GetOpenCode"://获取开奖号码
                    GetOpenCode(context);
                    break;
                case "GetMediaForecastList":
                    GetMediaForecastList(context);
                    break;
                case "GetMediaForecast_PageCount":
                    GetMediaForecast_PageCount(context);
                    break;
                case "GetForecastListByMediaId":
                    GetForecastListByMediaId(context);
                    break;
                case "GetForecastbyMedia_PageCount":
                    GetForecastbyMedia_PageCount(context);
                    break;
                case "GetForecastData_ByMediaId":
                    GetForecastData_ByMediaId(context);
                    break;
                case "DeleYuCe":
                    DeleYuCe(context);
                    break;
                default:
                    break;
            }
        }
        catch
        {
            alertmessage("操作异常");
        }
    }
    void FaBuMeiTiYuCe(HttpContext context)
    {
        loginUserInfo = BLL.CMember.UserLoginInfo();
        if (loginUserInfo == null)
        {
            alertmessageAndGo("请先登录！", "/Default.aspx");
            return;
        }
        else
        {
            if (loginUserInfo.Id > 0)
            {

                long MediaUserId = loginUserInfo.Id;
                string MediaName = loginUserInfo.nickname;
                int LotteryType = int.Parse(context.Request["LotteryType"]);
                string LotteryQs = context.Request["LotteryQs"].ToString();
                string yRedball = context.Request["yRedball"].ToString();
                string yBlueball = context.Request["yBlueball"].ToString();
                string ForecastNo = yRedball + "+" + yBlueball;//预测方案
                int flag = BLL.MediaForecast.CreateForecast(MediaUserId, MediaName, LotteryType, LotteryQs, ForecastNo);
                context.Response.Write(flag);
            }
        }



    }
    void GetCurrentLotteryQs(HttpContext context)
    {
        int lotteryType = int.Parse(context.Request["LotteryType"]);
        string sql = "select Lotteryqs from LotteryQs where LotteryType=" + lotteryType;
        context.Response.ContentType = "text/plain";
        string qs = BLL.LotteryQs.GetPageListBysql(sql).Rows[0][0].ToString();
        context.Response.Write(JsonConvert.SerializeObject(qs));
    }
    void GetTop10Data_ssq(HttpContext context)
    {
        string sql = "select top(10) id,LotteryQS from LotteryAnnouncement where LotteryType=1 order by openTime desc";
        List<Model.LotteryAnnouncement> lotterydata = BLL.LotteryAnnouncement.GetList(sql);
        context.Response.ContentType = "text/plain";
        context.Response.Write(JsonConvert.SerializeObject(lotterydata));
    }
    void GetTop10Data_dlt(HttpContext context)
    {
        string sql = "select top(10) id,LotteryQS from LotteryAnnouncement where LotteryType=2 order by openTime desc";
        List<Model.LotteryAnnouncement> lotterydata = BLL.LotteryAnnouncement.GetList(sql);
        context.Response.ContentType = "text/plain";
        context.Response.Write(JsonConvert.SerializeObject(lotterydata));
    }
    void GetTop10Data_qlc(HttpContext context)
    {
        string sql = "select top(10) id,LotteryQS from LotteryAnnouncement where LotteryType=7 order by openTime desc";
        List<Model.LotteryAnnouncement> lotterydata = BLL.LotteryAnnouncement.GetList(sql);
        context.Response.ContentType = "text/plain";
        context.Response.Write(JsonConvert.SerializeObject(lotterydata));
    }

    void GetLotteryannouncement(HttpContext context)
    {
        string issum = context.Request.QueryString["issue"].ToString();
        string lotteryType = context.Request.QueryString["lotteryType"].ToString();

        string sql = "select * from LotteryAnnouncement where id=" + issum + " and LotteryType=" + lotteryType;
        Model.LotteryAnnouncement lotteryAnnouncedata = BLL.LotteryAnnouncement.GetModelBySql(sql);
        Model.LotteryAnnouncement_equal item_equal = new Model.LotteryAnnouncement_equal();
        item_equal.Issue = lotteryAnnouncedata.LotteryQS;
        item_equal.Code = lotteryAnnouncedata.LotteryNo.Replace(",", " ");
        item_equal.Date = lotteryAnnouncedata.openTime;
        item_equal.Pool = lotteryAnnouncedata.jiangChi;//奖池
        item_equal.Sales = Convert.ToInt64(lotteryAnnouncedata.jiangChi) / 2;//售出注数

        string level1_str = lotteryAnnouncedata.oneMoney.ToString() + ":" + lotteryAnnouncedata.oneCount.ToString();
        item_equal.Level1 = level1_str;
        string level2_str = lotteryAnnouncedata.twoMoney.ToString() + ":" + lotteryAnnouncedata.twoCount.ToString();
        item_equal.Level2 = level2_str;
        string level3_str = lotteryAnnouncedata.threeMoney.ToString() + ":" + lotteryAnnouncedata.threeCount.ToString();
        item_equal.Level3 = level3_str;
        List<List<string>> bigList = new List<List<string>>();
        List<string> detail_item = new List<string>();
        for (int i = 0; i < 6; i++)
        {
            switch (i++)
            {
                case 0:
                    detail_item.Add("一等奖");
                    detail_item.Add(lotteryAnnouncedata.oneMoney.ToString());
                    detail_item.Add(lotteryAnnouncedata.oneCount.ToString());
                    break;
                case 1:
                    detail_item.Add("二等奖");
                    detail_item.Add(lotteryAnnouncedata.twoMoney.ToString());
                    detail_item.Add(lotteryAnnouncedata.twoCount.ToString());
                    break;
                case 2:
                    detail_item.Add("三等奖");
                    detail_item.Add(lotteryAnnouncedata.threeMoney.ToString());
                    detail_item.Add(lotteryAnnouncedata.threeCount.ToString());
                    break;
                case 3:
                    detail_item.Add("四等奖");
                    detail_item.Add(lotteryAnnouncedata.fourMoney.ToString());
                    detail_item.Add(lotteryAnnouncedata.fourCount.ToString());
                    break;
                case 4:
                    detail_item.Add("五等奖");
                    detail_item.Add(lotteryAnnouncedata.fiveMoney.ToString());
                    detail_item.Add(lotteryAnnouncedata.fiveCount.ToString());
                    break;
                case 5:
                    detail_item.Add("六等奖");
                    detail_item.Add(lotteryAnnouncedata.sixMoney.ToString());
                    detail_item.Add(lotteryAnnouncedata.sixCount.ToString());
                    break;
                default:
                    break;

            }
            bigList.Add(detail_item);
        }
        item_equal.Level = bigList;
        System.Web.HttpContext.Current.Response.Write(JsonConvert.SerializeObject(item_equal));

    }
    void FaBuYuCe(HttpContext context)
    {
        long flag = 0;
        loginUserInfo = BLL.CMember.UserLoginInfo();
        if (loginUserInfo == null)
        {
            alertmessageAndGo("请先登录！", "/Default.aspx");
            return;
        }
        else
        {
            if (loginUserInfo.Id > 0)
            {
                Model.ForecastPost forecastPost = new Model.ForecastPost();
                forecastPost.AddTime = DateTime.Now;
                forecastPost.Content = context.Request["content"].ToString();
                forecastPost.LotteryType = int.Parse(context.Request["lotteryType"].ToString());
                forecastPost.Title = context.Request["title"].ToString();
                forecastPost.PostType = context.Request["postType"].ToString();
                forecastPost.UserID = Convert.ToInt32(loginUserInfo.Id);
                if (Convert.ToInt32(context.Request["id"]) > 0)
                {
                    forecastPost.id = Convert.ToInt32(context.Request["id"]);
                    flag = BLL.ForecastPost.Update(forecastPost);
                }
                else
                {
                    flag = BLL.ForecastPost.Add(forecastPost);
                }
                context.Response.Write(flag);
            }
        }
    }
    void GenTie(HttpContext context)
    {
        loginUserInfo = BLL.CMember.UserLoginInfo();
        if (loginUserInfo == null)
        {
            context.Response.Write(-1);
        }
        else
        {
            if (loginUserInfo.Id > 0)
            {
                Model.ForecastComment forecastComment = new Model.ForecastComment();
                forecastComment.AddTime = DateTime.Now;
                forecastComment.Comment = context.Request["comment"].ToString();
                forecastComment.PostId = int.Parse(context.Request["postId"].ToString());
                forecastComment.UserID = Convert.ToInt32(loginUserInfo.Id);
                long flag = BLL.ForecastComment.Add(forecastComment);
                context.Response.Write(flag);
            }
        }
    }
    void YanZhengMa(HttpContext context)
    {
        string trendsCode = "";//缓存动态验证码 
        try
        {
            trendsCode = System.Web.HttpContext.Current.Session["forecastYzm"].ToString();
        }
        catch { }
        if (string.IsNullOrEmpty(trendsCode) || string.IsNullOrEmpty(context.Request["yanZhengMa"]) || trendsCode.ToUpper() != context.Request["yanZhengMa"].ToUpper())
        {
            context.Response.Write(0);
        }
    }
    void GetYucestatistics(HttpContext context)
    {
        string issue = context.Request.QueryString["issue"].ToString();
        string lotterytype = context.Request.QueryString["lotteryType"].ToString();
        string ballcolor = context.Request.QueryString["ballcolor"].ToString();
        if (lotterytype == "1")//双色球
        {
            if (ballcolor == "1")//红球
            {
                List<Model.MediaForecaststatistics_ssq_red> list_ssq_red = new List<Model.MediaForecaststatistics_ssq_red>();
                string sqlstr = "select rnum1,rnum2,rnum3,rnum4,rnum5,rnum6,rnum7,rnum8,rnum9,rnum10,rnum11,rnum12,rnum13,rnum14,rnum15,rnum16,rnum17,rnum18,rnum19,rnum20,rnum21,rnum22,rnum23,rnum24,rnum25,rnum26,rnum27,rnum28,rnum29,rnum30,rnum31,rnum32,rnum33  from MediaForecaststatistics";
                sqlstr += " where LotteryType=1 and LotteryQs='" + issue + "'";
                list_ssq_red = BLL.MediaForecaststatistics_ssq_red.GetList(sqlstr);
                if (list_ssq_red == null)
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(0));
                }
                else
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list_ssq_red[0]));
                }

            }
            else//篮球
            {
                List<Model.MediaForecaststatistics_ssq_blue> list_ssq_blue = new List<Model.MediaForecaststatistics_ssq_blue>();
                string sqlstr = "select bnum1,bnum2,bnum3,bnum4,bnum5,bnum6,bnum7,bnum8,bnum9,bnum10,bnum11,bnum12,bnum13,bnum14,bnum15,bnum16 from MediaForecaststatistics ";
                sqlstr += " where LotteryType=1 and LotteryQs='" + issue + "'";
                list_ssq_blue = BLL.MediaForecaststatistics_ssq_blue.GetList(sqlstr);
                if (list_ssq_blue == null)
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(0));
                }
                else
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list_ssq_blue[0]));
                }

            }
        }
        else //大乐透
        {
            if (ballcolor == "1")
            {
                string sqlstr = "select rnum1,rnum2,rnum3,rnum4,rnum5,rnum6,rnum7,rnum8,rnum9,rnum10,rnum11,rnum12,rnum13,rnum14,rnum15,rnum16,rnum17,rnum18,rnum19,rnum20,rnum21,rnum22,rnum23,rnum24,rnum25,rnum26,rnum27,rnum28,rnum29,rnum30,rnum31,rnum32,rnum33,rnum34,rnum35  from MediaForecaststatistics";
                sqlstr += " where LotteryType=2 and LotteryQs='" + issue + "'";
                var list_red = BLL.MediaForecaststatistics_dlt_red.GetList(sqlstr);

                if (list_red == null)
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(0));
                }
                else
                {
                    Model.MediaForecaststatistics_dlt_red list_dlt_red = list_red[0];
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list_dlt_red));
                }

            }
            else
            {
                string sqlstr = "select bnum1,bnum2,bnum3,bnum4,bnum5,bnum6,bnum7,bnum8,bnum9,bnum10,bnum11,bnum12  from MediaForecaststatistics";
                sqlstr += " where LotteryType=2 and LotteryQs='" + issue + "'";
                var list_blue = BLL.MediaForecaststatistics_dlt_blue.GetList(sqlstr);
                if (list_blue == null)
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(0));
                }
                else
                {
                    Model.MediaForecaststatistics_dlt_blue list_dlt_blue = list_blue[0];
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list_dlt_blue));
                }

            }

        }

    }
    void GetOpenCode(HttpContext context)
    {
        string lotterytype = context.Request.QueryString["lotteryType"].ToString();
        string issum = context.Request.QueryString["issue"].ToString();
        string sql2 = "select LotteryNo from LotteryAnnouncement where LotteryType=" + lotterytype + " and LotteryQS='" + issum + "'";
        string openCode = BLL.LotteryAnnouncement.GetPageListBysql(sql2).Rows[0][0].ToString();
        HttpContext.Current.Response.Write(JsonConvert.SerializeObject(openCode));
    }

    void GetMediaForecastList(HttpContext context)
    {
        string lotterytype = context.Request.QueryString["lotteryType"].ToString();
        string paixuType = context.Request.QueryString["paixuType"].ToString();
        if (lotterytype == "1")//双色球
        {
            string issue = string.IsNullOrEmpty(context.Request.QueryString["issue"].ToString()) ? null : context.Request.QueryString["issue"].ToString();
            if (issue == null)
            {
                string sqls = "select Lotteryqs from LotteryQs where LotteryType=1";
                issue = BLL.LotteryQs.GetPageListBysql(sqls).Rows[0][0].ToString();
            }

            string sql = " and LotteryType=1 and LotteryQS='" + issue + "'";
            int currentPageIndex = int.Parse(context.Request.QueryString["currentPageIndex"].ToString());
            int PageSize = 10;
            int totalCount4 = 0;
            List<Model.MediaForecast> list = BLL.MediaForecast.GetPageList_Where(currentPageIndex - 1, PageSize, sql, out totalCount4);
            if (list == null)
            {
                HttpContext.Current.Response.Write(JsonConvert.SerializeObject(0));
            }
            else
            {
                List<Model.MediaForecast_Convert> viewList = new List<Model.MediaForecast_Convert>();
                foreach (Model.MediaForecast item in list)
                {
                    Model.MediaForecast_Convert m = new Model.MediaForecast_Convert();
                    if (item.LotteryNo == null)//没开奖
                    {
                        m.MediaName = item.MediaName;
                        m.MediaUserId = item.MediaUserId;
                        m.LotteryNo = null;
                        m.ForecastNo_red = BLL.MediaForecast.SplitString(item.ForecastNo)[0].Replace(",", " ");//预测红球
                        m.ForecastNo_blue = BLL.MediaForecast.SplitString(item.ForecastNo)[1].Replace(",", " ");//预测篮球
                        m.CurrentQS_MZ_red = 0;//本期命中红球个数
                        m.CurrengQs_MZ_blue = 0;//本期命中篮球个数
                        m.WonRate = BLL.MediaForecast.ComputeHistoryWinRute(item.MediaUserId, lotterytype);//历史中奖率
                        m.HistroyMZ_Most_red = BLL.MediaForecast.HistoryMost_MZ("1", item.MediaUserId).HistroyMZ_Most_red;//历史最高命中--红球
                        m.HistroyMZ_Most_blue = BLL.MediaForecast.HistoryMost_MZ("1", item.MediaUserId).HistroyMZ_Most_blue;//历史最高命中--篮球
                    }
                    else//已开奖
                    {

                        m.MediaName = item.MediaName;
                        m.MediaUserId = item.MediaUserId;
                        m.LotteryNo = item.LotteryNo;
                        m.ForecastNo_red = BLL.MediaForecast.SplitString(item.ForecastNo)[0].Replace(",", " ");//预测红球
                        m.ForecastNo_blue = BLL.MediaForecast.SplitString(item.ForecastNo)[1].Replace(",", " ");//预测篮球
                        m.CurrentQS_MZ_red = BLL.MediaForecast.RedNum(item.Mredball);//本期命中红球个数
                        m.CurrengQs_MZ_blue = BLL.MediaForecast.BlueNum(item.Mblueball);//本期命中篮球个数
                        m.WonRate = BLL.MediaForecast.ComputeHistoryWinRute(item.MediaUserId, lotterytype);//历史中奖率
                        m.HistroyMZ_Most_red = BLL.MediaForecast.HistoryMost_MZ("1", item.MediaUserId).HistroyMZ_Most_red;//历史最高命中--红球
                        m.HistroyMZ_Most_blue = BLL.MediaForecast.HistoryMost_MZ("1", item.MediaUserId).HistroyMZ_Most_blue;//历史最高命中--篮球
                    }

                    viewList.Add(m);
                }
                if (paixuType == "1")//默认排序
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(viewList));
                }
                else if (paixuType == "2")//历史最高中奖率排序
                {
                    var listHistory = (from c in viewList orderby c.WonRate descending select c).ToList();
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(listHistory));
                }
                else//历史最高命中排序
                {
                    var listMoszMZList = (from c in viewList orderby c.HistroyMZ_Most_red descending, c.HistroyMZ_Most_blue descending select c).ToList();
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(listMoszMZList));
                }
            }
        }
        else//大乐透
        {
            string issue = string.IsNullOrEmpty(context.Request.QueryString["issue"].ToString()) ? null : context.Request.QueryString["issue"].ToString();
            if (issue == null)
            {
                string sqls = "select Lotteryqs from LotteryQs where LotteryType=2";
                issue = BLL.LotteryQs.GetPageListBysql(sqls).Rows[0][0].ToString();
            }

            string sql = " and LotteryType=2 and LotteryQS='" + issue + "'";
            int currentPageIndex = int.Parse(context.Request.QueryString["currentPageIndex"].ToString());
            int PageSize = 10;
            int totalCount4 = 0;
            List<Model.MediaForecast> list = BLL.MediaForecast.GetPageList_Where(currentPageIndex - 1, PageSize, sql, out totalCount4);
            if (list == null)
            {
                HttpContext.Current.Response.Write(JsonConvert.SerializeObject(0));
            }
            else
            {
                List<Model.MediaForecast_Convert> viewList = new List<Model.MediaForecast_Convert>();
                foreach (Model.MediaForecast item in list)
                {
                    Model.MediaForecast_Convert m = new Model.MediaForecast_Convert();
                    if (item.LotteryNo == null || item.LotteryNo == "")//没开奖
                    {
                        m.MediaName = item.MediaName;
                        m.MediaUserId = item.MediaUserId;
                        m.LotteryNo = null;
                        m.ForecastNo_red = BLL.MediaForecast.SplitString(item.ForecastNo)[0].Replace(",", " ");//预测红球
                        m.ForecastNo_blue = BLL.MediaForecast.SplitString(item.ForecastNo)[1].Replace(",", " ");//预测篮球
                        m.CurrentQS_MZ_red = 0;//本期命中红球个数
                        m.CurrengQs_MZ_blue = 0;//本期命中篮球个数
                        m.WonRate = BLL.MediaForecast.ComputeHistoryWinRute(item.MediaUserId, lotterytype);//历史中奖率
                        m.HistroyMZ_Most_red = BLL.MediaForecast.HistoryMost_MZ("1", item.MediaUserId).HistroyMZ_Most_red;//历史最高命中--红球
                        m.HistroyMZ_Most_blue = BLL.MediaForecast.HistoryMost_MZ("1", item.MediaUserId).HistroyMZ_Most_blue;//历史最高命中--篮球
                    }
                    else//已开奖
                    {

                        m.MediaName = item.MediaName;
                        m.MediaUserId = item.MediaUserId;
                        m.LotteryNo = item.LotteryNo;
                        m.ForecastNo_red = BLL.MediaForecast.SplitString(item.ForecastNo)[0].Replace(",", " ");//预测红球
                        m.ForecastNo_blue = BLL.MediaForecast.SplitString(item.ForecastNo)[1].Replace(",", " ");//预测篮球
                        m.CurrentQS_MZ_red = BLL.MediaForecast.RedNum(item.Mredball);//本期命中红球个数
                        m.CurrengQs_MZ_blue = BLL.MediaForecast.BlueNum(item.Mblueball);//本期命中篮球个数
                        m.WonRate = BLL.MediaForecast.ComputeHistoryWinRute(item.MediaUserId, lotterytype);//历史中奖率
                        m.HistroyMZ_Most_red = BLL.MediaForecast.HistoryMost_MZ("2", item.MediaUserId).HistroyMZ_Most_red;//历史最高命中--红球
                        m.HistroyMZ_Most_blue = BLL.MediaForecast.HistoryMost_MZ("2", item.MediaUserId).HistroyMZ_Most_blue;//历史最高命中--篮球
                    }

                    viewList.Add(m);
                }
                if (paixuType == "1")//默认排序
                {
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(viewList));
                }
                else if (paixuType == "2")//历史最高中奖率排序
                {
                    var listHistory = (from c in viewList orderby c.WonRate descending select c).ToList();
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(listHistory));
                }
                else//历史最高命中排序
                {
                    var listMoszMZList = (from c in viewList orderby c.HistroyMZ_Most_red descending, c.HistroyMZ_Most_blue descending select c).ToList();
                    HttpContext.Current.Response.Write(JsonConvert.SerializeObject(listMoszMZList));
                }
            }

        }
    }

    void GetMediaForecast_PageCount(HttpContext context)
    {
        string issue = string.IsNullOrEmpty(context.Request.QueryString["issue"].ToString()) ? null : context.Request.QueryString["issue"].ToString();
        string LotteryType = context.Request.QueryString["LotteryType"].ToString();
        if (issue == null)
        {
            string sqls = "select Lotteryqs from LotteryQs where LotteryType=" + LotteryType;
            issue = BLL.LotteryQs.GetPageListBysql(sqls).Rows[0][0].ToString();
        }
        string sqlstr = "select count(0) from MediaForecast where LotteryType=" + LotteryType + " and LotteryQS=" + issue + "";
        int CountNum = BLL.MediaForecast.GetPageListBysql(sqlstr).Rows.Count;
        int PageCount = 0;
        if (CountNum % 10 == 0)
        {
            PageCount = CountNum / 10;
        }
        else
        {
            PageCount = CountNum / 10 + 1;
        }
        HttpContext.Current.Response.Write(JsonConvert.SerializeObject(PageCount));
    }

    void GetForecastbyMedia_PageCount(HttpContext context)
    {
        string id = context.Request.QueryString["id"].ToString();
        string LotteryType = context.Request.QueryString["LotteryType"].ToString();
        string sqlstr = "select count(Id) from MediaForecast where LotteryType=" + LotteryType + " and MediaUserId=" + id + "";
        int RowNum = BLL.MediaForecast.GetPageListBysql(sqlstr).Rows.Count;
        int pageCount = 0;
        if (RowNum % 10 == 0)
        {
            pageCount = RowNum / 10;
        }
        else
        {
            pageCount = RowNum / 10 + 1;
        }
        HttpContext.Current.Response.Write(JsonConvert.SerializeObject(pageCount));

    }
    void GetForecastListByMediaId(HttpContext context)
    {
        string id = context.Request.QueryString["id"].ToString();
        string LotteryType = context.Request.QueryString["LotteryType"].ToString();
        int currentPageIndex = int.Parse(context.Request.QueryString["currentPageIndex"].ToString());
        string paixuType = context.Request.QueryString["paixuType"].ToString();
        int PageSize = 10;

        string sqlstr = " MediaUserId=" + id + " and LotteryType=" + LotteryType + "";
        List<Model.MediaForecast> list = BLL.MediaForecast.GetPageList_Where1(currentPageIndex - 1, PageSize, sqlstr);
        if (list == null)
        {
            HttpContext.Current.Response.Write(JsonConvert.SerializeObject(0));
        }
        else
        {
            List<Model.MediaForecast_Convert> viewList = new List<Model.MediaForecast_Convert>();

            foreach (Model.MediaForecast mf in list)
            {
                Model.MediaForecast_Convert m = new Model.MediaForecast_Convert();
                if (mf.LotteryNo == null || mf.LotteryNo == "")//未开奖
                {
                    m.LotteryQS = mf.LotteryQS;
                    m.LotteryNo = "等待开奖";
                    m.ForecastNo = mf.ForecastNo.Replace(",", " ");
                    m.WinLevel = 0;
                }
                else//已开奖
                {
                    m.LotteryQS = mf.LotteryQS;
                    m.LotteryNo = mf.LotteryNo;
                    string[] lotteryNo = mf.LotteryNo.Split('+');
                    m.RedBall = lotteryNo[0].Replace(",", " ");
                    m.BlueBall = lotteryNo[1].Replace(",", " ");
                    m.ForecastNo = mf.ForecastNo.Replace(",", " ");
                    m.WinLevel = mf.WinLevel;
                }
                viewList.Add(m);
            }

            if (paixuType == "1")//按期次排序
            {
                var listByQs = (from c in viewList orderby c.LotteryQS descending select c).ToList();
                HttpContext.Current.Response.Write(JsonConvert.SerializeObject(listByQs));
            }
            else//按命中奖级排序
            {
                var listByWinLevel = (from c in viewList orderby c.WinLevel descending select c).ToList();
                HttpContext.Current.Response.Write(JsonConvert.SerializeObject(listByWinLevel));
            }
        }
    }
    void GetForecastData_ByMediaId(HttpContext context)
    {
        string id = context.Request.QueryString["id"].ToString();
        string LotteryType = context.Request.QueryString["LotteryType"].ToString();
        string sqlstr = " MediaUserId=" + id + " and LotteryType=" + LotteryType + "";
        string sql2 = "select * from MediaForecast where LotteryType=" + LotteryType + " and MediaUserId = '" + id + "'";
        List<Model.MediaForecast> mf_list = BLL.MediaForecast.GetList(sql2);
        Model.MediaForecast_Convert mc = new Model.MediaForecast_Convert();
        mc.MediaName = mf_list[0].MediaName;
        mc.ForecastQSCount = mf_list.Count;
        mc.WonRate = BLL.MediaForecast.ComputeHistoryWinRute(Convert.ToInt64(id), LotteryType);
        mc.BlueBall_AverageMZRate = BLL.MediaForecast.ComputeRedBallWin(mf_list).BlueBall_AverageMZRate;
        mc.RedBall_AverageMZCount = BLL.MediaForecast.ComputeRedBallWin(mf_list).RedBall_AverageMZCount;
        string mzMost = BLL.MediaForecast.ComputeRedBallWin(mf_list).MZ_Most;
        mc.MZ_Most = mzMost.Substring(0, mzMost.Length - 1);
        HttpContext.Current.Response.Write(JsonConvert.SerializeObject(mc));
    }
    void DeleYuCe(HttpContext context)
    {
        string[] ids = context.Request["id"].ToString().Split(',');
        for (int i = 0; i < ids.Count(); i++)
        {
            BLL.ForecastPost.Delete(Convert.ToInt32(ids[i]));
        }
        context.Response.Write(1);
    }

}

